<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }



//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.
if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', news, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}


//get md5 password and move to temp table
/*	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$values = get_user_info($attendee_id);
		$password = addslashes($values['new_pass']);
		$query = "UPDATE attendee SET password = '$password' WHERE attendee_id = '$attendee_id'";
		echo "$query<br />\n";
		pg_query($query);
		unset($password);
		}
*/

//get unecrypted password and move to new_pass field.
/*	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$values = get_user_info($attendee_id);
		$password = addslashes($values['password']);
		$query = "UPDATE attendee SET new_pass = '$password' WHERE attendee_id = '$attendee_id'";
		echo "$query<br />\n";
		pg_query($query);
		unset($password);
		}
*/


//get unecrypted password from new_pass field and move to password field as encrypted string.
/*	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$values = get_user_info($attendee_id);
		$crypt_pass = crypt($values['new_pass']); # let salt be generated
		$crypt_pass = addslashes($crypt_pass);
		$query = "UPDATE attendee SET password = '$crypt_pass' WHERE attendee_id = '$attendee_id'";
		echo "$query<br />\n";
		pg_query($query);
		unset($crypt_pass);
		}
*/

/*
//Move email_addr around.
	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$values = get_user_info($attendee_id);
		$email_addr = addslashes(strtolower($values['email_addr_new']));
		$query = "UPDATE attendee SET email_addr = '$email_addr' WHERE attendee_id = '$attendee_id'";
//		echo "$query<br />\n";
		pg_query($query);
		unset($email_addr);
		}
*/



/*
//Move info in registration table into the event registration table.
	if (!db_connect())
		return false;
	$query = "SELECT * FROM registration";
   $result = pg_query($query);
   $result = db_result_to_array($result);
	foreach ($result as $reg_record) {
		$cost = get_event_cost($reg_record['event_id']);
		$reg_record['cost'] = $cost;
		$query = "INSERT INTO event_reg (attendee_id, event_id, starting_timeslot, cost, reg_status, entered) VALUES ('".$reg_record['attendee_id']."', '".$reg_record['event_id']."', '".$reg_record['starting_timeslot']."', '".$reg_record['cost']."', '".$reg_record['registration_status']."', 'now()')";
//		echo "$query<br />\n";
		pg_query($query);
		unset($cost);
		}
*/


/*
//Move info out of attendee into convention registration.
	if (!db_connect())
		return false;
	$query = "SELECT attendee_id, event_day, registration_status FROM attendee WHERE event_day != ''";
   $result = pg_query($query);
   $result = db_result_to_array($result);
	foreach ($result as $reg_record) {
			$reg_record['reg_type'] = 'general admit pre-reg';
		if ($reg_record['event_day'] == 'all week-end') $con_cost = '22.00';
		if ($reg_record['event_day'] == 'friday') $con_cost = '10.00';
		if ($reg_record['event_day'] == 'saturday') $con_cost = '15.00';
		if ($reg_record['event_day'] == 'sunday') $con_cost = '15.00';
		
		if ($gmevents = get_gm_events($reg_record['attendee_id'])) $gmnum =
			pg_numrows($gmevents);
		if ($cogmevents = get_cogm_events($reg_record['attendee_id'], approved))
			$cogmnum = pg_numrows($cogmevents);
		if ($cogmevents = get_cogm_events($reg_record['attendee_id'], pending))
			$cogmnumpending = pg_numrows($cogmevents);
		$runningevents = $gmnum + $cogmnum;
		if ($runningevents >= '4') {
			$con_cost = '0.00';
			$reg_record['reg_type'] = 'gm';
			}
		$reg_record['amount_paid'] = $con_cost;
		$query = "INSERT INTO con_reg (attendee_id, event_day, reg_type, cost, reg_status, entered) VALUES ('".$reg_record['attendee_id']."', '".$reg_record['event_day']."', '".$reg_record['reg_type']."', '".$reg_record['amount_paid']."', '".$reg_record['registration_status']."', 'now()')";
//		echo "$query<br />\n";
		pg_query($query);
		unset($con_cost, $runningevents, $gmnum, $cogmnum, $cogmnumpending);
		}
*/

/*
//Calculates the amount people have paid us and enters it in their record.
	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		//first we will get how much they paid for their convention reg.
		$query = "SELECT cost FROM con_reg WHERE attendee_id = '$attendee_id' AND reg_status = 'approved'";
		$result = pg_query("$query");
		if (pg_num_rows($result) > 0)
			$con_amount_paid = floatval(pg_fetch_result($result,0,"cost"));
	
		 //Now we get a list of all events they are participating in and iterate through that to total the cost of those events.
		$result = get_attend_events($attendee_id, approved);
		$event_array = db_result_to_array($result);
		foreach ($event_array as $row) {
			$rowamountpaid = get_event_amount_paid($row['event_id'], $row['starting_timeslot'], $attendee_id);
			$event_amount_paid += "$rowamountpaid";
			unset($rowamountpaid);
			}
		//$result = pg_query("SELECT amount_owed FROM attendee WHERE attendee_id = '$attendee_id'");
		//if (pg_num_rows($result) == 0)
		//return false;
		//$amount_owed = floatval(pg_fetch_result($result,0,"amount_owed"));
		$amount_owed = $con_amount_paid + $event_amount_paid;
		if ($amount_owed > 0) {
			$query = "UPDATE attendee SET amount_paid = '$amount_owed' WHERE attendee_id = '$attendee_id'";
			echo "$query<br />\n";
			$result = pg_query("$query");
			}
		unset($attendee_id, $amount_owed, $con_amount_paid, $event_amount_paid);
		}
*/


/*
//Set peoples names to upper case starting letters and change usernames and email_addresses to lower case.
	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$values = get_user_info($attendee_id);
		$first_name = addslashes(ucfirst($values['first_name']));
		$last_name = addslashes(ucfirst($values['last_name']));
		$username = addslashes(strtolower($values['username']));
		$email_addr = addslashes(strtolower($values['email_addr']));
		$query = "UPDATE attendee SET first_name = '$first_name', last_name = '$last_name', username = '$username', email_addr = '$email_addr' WHERE attendee_id = '$attendee_id'";
//		echo "$query<br />\n";
		pg_query($query);
		unset($attendee_id, $last_name, $first_name, $username, $email_addr);
		}
*/

/*
//Clear all entries in the aount_paid field
	$conn = db_connect();
	if (!$conn)
		return false;
	$query = "SELECT attendee_id FROM attendee ORDER BY attendee_id ASC";
	$result = pg_query($query);
	$attendee_id_array = db_result_to_array($result);
	foreach ($attendee_id_array as $id_row) {
		$attendee_id = $id_row['attendee_id'];
		$query = "UPDATE attendee SET amount_paid = '0.00' WHERE attendee_id = '$attendee_id'";
//		echo "$query<br />\n";
		pg_query($query);
		unset($attendee_id);
		}
*/

/*
//We enter people who are running events but not registered in the database
	if (!db_connect())
		return false;
	$result = get_event_list();
	$result = db_result_to_array($result);
	foreach ($result as $reg_record) {
			$working_id = $reg_record['attendee_id'];
			if (!get_con_reg_info($working_id)) {
				$event_day = "all week-end";
				$reg_type = 'general admit pre-reg';
				$con_cost = '22.00';
				if ($gmevents = get_gm_events($reg_record['attendee_id'])) $gmnum =
					pg_numrows($gmevents);
				if ($cogmevents = get_cogm_events($reg_record['attendee_id'], approved))
					$cogmnum = pg_numrows($cogmevents);
				if ($cogmevents = get_cogm_events($reg_record['attendee_id'], pending))
					$cogmnumpending = pg_numrows($cogmevents);
				$runningevents = $gmnum + $cogmnum;
				if ($runningevents >= '4') {
					$con_cost = '0.00';
					$reg_type = 'gm';
					}
				insert_con_registration($working_id, $event_day, $reg_type, $con_cost, approved);
				unset($con_cost, $runningevents, $gmnum, $cogmnum, $cogmnumpending, $event_day, $reg_type);
			}
		}
*/

?>
